<%@page language="java" pageEncoding="UTF-8" contentType="text/html;charset=utf-8"%>
<%@include file="/includes/taglibs.jsp"%>
<%@page import="com.feib.stms.action.BaseDoUploadFileActionbean"%>


<%
// 欄位排序處理
BaseDoUploadFileActionbean actionBean = (BaseDoUploadFileActionbean) request.getAttribute("actionBean");
actionBean.setNavigator();
pageContext.setAttribute("actionBeanClassName", actionBean.getClass().getName());
%>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
    "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
    <title></title>
        
    <script type="text/javascript">
    <!-- 
    $(document).ready(function() {
 
<c:if test="${null != actionBean.queryResult && not empty actionBean.queryResult.paginatedList}">

		$('#doExportExcelFileBtn').click(function() {
			$("#hidden\\.doExportExcelFileBtn").trigger('click');
		});
	
		$("[id^='doDeleteUploadFileBtn-']").click(function() {
			var uploadFilePk = this.id.substring(22);
			
			$('#messageDiv').dialog('destroy');
            $('#messageDiv').show();
            $('#messageDiv').html("是否確定刪除?");
            
            $("#messageDiv" ).dialog({
            title:'<span class="ui-icon ui-icon-info" style="float: left; margin-right: .3em;"></span><strong>訊息</strong>' 
                , width: 300
                , resizable: false
                , modal: true        
                , overlay: {
                    backgroundColor: '#000',
                    opacity: 0.9
                }
                , buttons: {
                    Ok: function() {
                        $( this ).dialog( "close" ); 
                       	$('#hidden\\.deleteUploadFilePk').val(uploadFilePk);
						$("#hidden\\.doDeleteBtn").trigger('click');
                    },
                    Cancel: function() {
                        $( this ).dialog( "close" );                    
                    }
                }
            }).prev().addClass('ui-state-highlight');
			
		});

				
		$("[id^='viewDetail-']").click(function() {
			var uploadFilePk = this.id.substring(11);
         	var url = '<c:url value="/Stms3005.action"/>?decorator=showModalDialogTemplate&confirm=true&doQueryWithSowModalDialog=&qryPymentFileContent.uploadFile.uploadFilePk='+uploadFilePk;
         	var varOptions = 'help:no;status:no;scroll:yes;resize:yes;center:yes;dialogHeight:700px;dialogWidth:1000px';
        	var dialogArguments = new Object();
        	 	dialogArguments.parentWindowObj = self;
         	var s1 = showModalDialog(url, dialogArguments, varOptions);
		 return true;                
        });
		

		$("[id^='a-sortHeader-']").click(function() {
			var sortField = this.id.substring(13);
			$('#hidden\\.queryResult\\.sortCriterion').val(sortField);
					
			var clazz = $(this).attr('class');
			if (null == clazz || 0 == clazz.length)
				$('#hidden\\.queryResult\\.sortDirection').val('1');
			else if ('sortAsc' == clazz)
				$('#hidden\\.queryResult\\.sortDirection').val('1');
			else
				$('#hidden\\.queryResult\\.sortDirection').val('2');
				
			$('#hidden\\.queryResult\\.pageNumber').val('1');
			
			waitingDialog({});
			$("#hidden\\.doQueryBtn").trigger('click');
			return false;
			
		});
		
		$("[id^='firstPageBtn']").click(function() {
			$('#hidden\\.queryResult\\.pageNumber').val('1');
			waitingDialog({});
			$("#hidden\\.doQueryBtn").trigger('click');
		});
		
		$("[id^='prePageBtn']").click(function() {
			$('#hidden\\.queryResult\\.pageNumber').val('<c:out value="${prePageNumber}"/>');
			waitingDialog({});
			$("#hidden\\.doQueryBtn").trigger('click');
		});
		
		$("[id^='nextPageBtn']").click(function() {
			$('#hidden\\.queryResult\\.pageNumber').val('<c:out value="${nextPageNumber}"/>');
			waitingDialog({});
			$("#hidden\\.doQueryBtn").trigger('click');
		});
		
		$("[id^='lastPageBtn']").click(function() {
			$('#hidden\\.queryResult\\.pageNumber').val('<c:out value="${lastPageNumber}"/>');
			waitingDialog({});
			$("#hidden\\.doQueryBtn").trigger('click');
		});
		
		$("[id^='currentPageText']").change(function() {
			var value = this.value;
			if (value != ''){
				value = value.replace(/^\s\s*/, '').replace(/\s\s*$/, '');
				var intRegex = /^\d+$/;
				if(!intRegex.test(value)) {
					showErrorMessageDialog('頁數必須是整數');
					return ;
				}
				
				value = parseInt(value, 10);
				
				if (value < 1){
					showErrorMessageDialog('頁數必須是大於1');
					return ;
				}
				else if (value > <c:out value='${lastPageNumber}'/>){
					showErrorMessageDialog('頁數必須是小於總頁數 (<c:out value="${lastPageNumber}"/>)');
					return ;
				}
				else if (value != <c:out value='${currentPageNumber}'/>){
					doQueryAction();
					$('#hidden\\.queryResult\\.pageNumber').val(value);
					waitingDialog({});
					$("#hidden\\.doQueryBtn").trigger('click');
					return ;
				}
				
			}
			else{
				showErrorMessageDialog('頁數不可為空白)');
				return ;
			}
		});
</c:if>
		 	
    	<c:if test="${not empty actionBean.message}">
    	showMessageDialog('<c:out value="${actionBean.message }" escapeXml="false"/>');
    	</c:if>
    	
    	<c:if test="${not empty actionBean.errorMessage}">
    	showErrorMessageDialog('<c:out value="${actionBean.errorMessage }" escapeXml="false"/>');
    	</c:if>
                  
    });
    
   
    
    
    
    function doPrintEvent()
    {
    	divPrint('listForm');
    	return false;
    }
    
    function doUploadFileCheckAction()
	{
		var isDoCheck = false;
		$('#confirmHiddenFrom input:checkbox.chk').each(function(){               
        	if ( $(this).attr('checked') ){
        		isDoCheck = true;
        	}
       	});
       	
		if(isDoCheck){		
			$('#messageDiv').dialog('destroy');
            $('#messageDiv').show();
            $('#messageDiv').html("是否確定審查 ?");
            
            $("#messageDiv" ).dialog({
            title:'<span class="ui-icon ui-icon-info" style="float: left; margin-right: .3em;"></span><strong>訊息</strong>' 
                , width: 300
                , resizable: false
                , modal: true        
                , overlay: {
                    backgroundColor: '#000',
                    opacity: 0.9
                }
                , buttons: {
                    Ok: function() {
                        $( this ).dialog( "close" ); 
                       	$("#hidden\\.doCheckBtn").trigger('click');
                    },
                    Cancel: function() {
                        $( this ).dialog( "close" );
                      
                    }
                }
            }).prev().addClass('ui-state-highlight');			
			
		}else{		
           	 	showErrorMessageDialog('至少選擇一筆');			
                return false;
		}
	}
    
    function doCheckAll()
    {
		$('#confirmHiddenFrom input:checkbox.chk').each(function(){              
        	$(this).attr("checked", true);
       });
	}
	
	function unDoCheckAll()
	{
		$('#confirmHiddenFrom input:checkbox.chk').each(function(){               
        	$(this).attr("checked", false);
       });
	}
    //-->
    </script>
</head>
<body>
	<div id="smallQueryForm"></div>
	
	<div id="queryForm"></div>
	
	<div id="listForm">


			<div id="paginationBar" style=" margin: 0 auto;">
			<input type="button" id="firstPageBtn" class="formBtn" value="第一頁" <c:out value='${prePageNumber<=0 ? "disabled": "" }'/> />
			<input type="button" id="prePageBtn" class="formBtn" value="上一頁" <c:out value='${prePageNumber<=0 ? "disabled": "" }'/> />
			第 <input type="text" id="currentPageText" class="formBtn" value="${currentPageNumber }" size="3" maxlength="4" /> / ${lastPageNumber} 頁
			<input type="button" id="nextPageBtn" class="formBtn" value="下一頁" <c:out value='${lastPageNumber<nextPageNumber ? "disabled": "" }'/> />
			<input type="button" id="lastPageBtn" class="formBtn" value="最末頁" <c:out value='${lastPageNumber<=currentPageNumber ? "disabled": "" }'/> />
			</div>
		
<stripes:form name="confirmHiddenFrom" id="confirmHiddenFrom" beanclass="<%=actionBean.getClass().getName() %>" method="post" >	
	<table id="queryResultTable">
				<thead>
					<tr>
						<th>&nbsp;</th>
						<th><a id='a-sortHeader-fileFormatName' href='javascript:void(0);' class="<c:out value='${fileFormatNameSortedClass }'/>"> <c:out value='${fileFormatNameSortedSpan }' escapeXml="false"/>放行資料</a> </th>
						<th><a id='a-sortHeader-fileName' href='javascript:void(0);' class="<c:out value='${fileNameSortedClass }'/>"> <c:out value='${fileNameSortedSpan }' escapeXml="false"/>檔案名稱</a> </th>
						<th><a id='a-sortHeader-totalNetIncomeCount' href='javascript:void(0);' class="<c:out value='${totalNetIncomeCountChkSortedClass }'/>"> <c:out value='${totalNetIncomeCountSortedSpan }' escapeXml="false"/>淨收筆數</a></th>
						<th><a id='a-sortHeader-totalNetIncome' href='javascript:void(0);' class="<c:out value='${totalNetIncomeSortedClass }'/>"> <c:out value='${totalNetIncomeSortedSpan }' escapeXml="false"/>淨收金額</a></th>
                        <th><a id='a-sortHeader-totalNetPayCount' href='javascript:void(0);' class="<c:out value='${totalNetPayCountSortedClass }'/>"> <c:out value='${totalNetPayCountSortedSpan }' escapeXml="false"/>淨付筆數</a></th>
                        <th><a id='a-sortHeader-totalNetPay' href='javascript:void(0);' class="<c:out value='${totalNetPaySortedClass }'/>"><c:out value='${totalNetPaySortedSpan }' escapeXml="false"/>淨付金額</a></th>
                        <th><a id='a-sortHeader-chksum' href='javascript:void(0);' class="<c:out value='${chksumSortedClass }'/>"> <c:out value='${chksumChkSortedSpan }' escapeXml="false"/>總檢核數</a></th>
                         <th><a id='a-sortHeader-deliveryAccount' href='javascript:void(0);' class="<c:out value='${deliveryAccountSortedClass }'/>"> <c:out value='${deliveryAccountSortedSpan }' escapeXml="false"/>交割帳號</a></th>
                         <th>刪除</th>
                         <th>明細</th> 
                     </tr>
				</thead>
<c:choose>
<c:when test="${null != actionBean.queryResult && not empty actionBean.queryResult.paginatedList}">				
				<tbody>
                    <c:forEach items="${actionBean.queryResult.paginatedList}" var="viewObj" varStatus="rowstat">
                    <tr>
                       <td align="center">
						<input name="checkUploadFiles[${rowstat.index}].uploadFilePk" 
							type="checkbox" 
							id="checkUploadFiles[${rowstat.index}].uploadFilePk" 
							value="<c:out value='${viewObj.uploadFilePk}'/>" class="chk"/>
						</td>
                        <td><c:out value="${viewObj.fileFormatName }" /></td>
                        
                        <input name="checkUploadFiles[${rowstat.index}].fileName" 
						type="hidden" 
						 	id="checkUploadFiles[${rowstat.index}].fileName" 
							value="<c:out value='${viewObj.fileName}'/>" />
                        
                        
                        <td><c:out value="${viewObj.fileName }" /></td>
                        <td align="right"><fmt:formatNumber value="${viewObj.totalNetIncomeCount}" pattern="##,###" /></td>            
                        <td align="right"><fmt:formatNumber value="${viewObj.totalNetIncome}" pattern="##,###" /></td>                     
                        <td align="right"><fmt:formatNumber value="${viewObj.totalNetPayCount}" pattern="##,###" /></td>                      
                        <td align="right"><fmt:formatNumber value="${viewObj.totalNetPay}" pattern="##,###" /></td>
                        <td><c:out value="${viewObj.formatedChksum }" /></td>
                        <td><c:out value="${viewObj.formatedPreDesignatedAccount }" /></td>
                        	<input name="checkUploadFiles[${rowstat.index}].securitiesNo"  type="hidden" 
				  			       id="checkUploadFiles[${rowstat.index}].securitiesNo"  
								   value="<c:out value='${viewObj.securitiesNo}'/>" />   
						<td>	                
							<input id="doDeleteUploadFileBtn-${viewObj.uploadFilePk}" name="doDeleteUploadFileBtn" value="刪除" type="button" />				
                        </td>
                        <td>
                        	<div id="viewDetail-<c:out value='${viewObj.uploadFilePk}'/>" class="widgetsIcon ui-state-default ui-corner-all" title="檢視"><span class="ui-icon ui-icon-circle-triangle-e"></span></div>
                        </td>
                        </tr>
                        </c:forEach>
                      
                      <c:if test="${null != actionBean.queryResult.totalObject }">
                    <tr>
                        <td align="right">總計</td>
                        <td colspan="15">
                        	筆數:&nbsp;<c:choose><c:when test="${null != actionBean.queryResult.totalObject.recordCount }"><strong><fmt:formatNumber value="${actionBean.queryResult.totalObject.recordCount}" pattern="##,###" /></strong></c:when><c:otherwise>0</c:otherwise></c:choose>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
                         	淨收筆數:&nbsp;<c:choose><c:when test="${null != actionBean.queryResult.totalObject.totalNetIncomeCount }"><strong><fmt:formatNumber value="${actionBean.queryResult.totalObject.totalNetIncomeCount}" pattern="##,###" /></strong></c:when><c:otherwise>0</c:otherwise></c:choose>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
                        	淨收金額:&nbsp;<c:choose><c:when test="${null != actionBean.queryResult.totalObject.totalNetIncome }"><strong><fmt:formatNumber value="${actionBean.queryResult.totalObject.totalNetIncome}" pattern="##,###" /></strong></c:when><c:otherwise>0</c:otherwise></c:choose>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
                        	淨付筆數:&nbsp;<c:choose><c:when test="${null != actionBean.queryResult.totalObject.totalNetPayCount }"><strong><fmt:formatNumber value="${actionBean.queryResult.totalObject.totalNetPayCount}" pattern="##,###" /></strong></c:when><c:otherwise>0</c:otherwise></c:choose>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
                        	淨付金額:&nbsp;<c:choose><c:when test="${null != actionBean.queryResult.totalObject.totalNetPay }"><strong><fmt:formatNumber value="${actionBean.queryResult.totalObject.totalNetPay}" pattern="##,###" /></strong></c:when><c:otherwise>0</c:otherwise></c:choose>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;    
                        </td>
                    </tr>
                    </c:if>
				</tbody>	
			
			<tfoot>
				<tr>
					<td colspan="15" class="listFunction">
					<input type="button" id="checkAll" name="checkAll" value="全選" onclick="javascript: doCheckAll();" class="formBtn"/>
					<input type="button" id="unCheckAll" name="unCheckAll" value="全不選" onclick="javascript: unDoCheckAll();" class="formBtn"/>
					<input id="doCheckBtn" name="doCheckBtn" value="審查" type="button" class="formBtn" onclick="javascript:return doUploadFileCheckAction();"/> 
					<input type="button" value="列印" onclick="javascript:doPrintEvent();" class="formBtn" /></td>
				</tr>
			</tfoot>
</c:when>
	<c:otherwise>
  		<tbody>
  				 <tr>
   					<td colspan="15" align="center" >查無資料</td>
   				</tr>
  		</tbody> 
	</c:otherwise>	
</c:choose>	
			

	</table>
	
			<div style="display: none;">
					<stripes:submit id="hidden.doCheckBtn" name="doCheck" value="審查" class="formBtn"/>				
			</div>

</stripes:form>			
			

	</div>
	
<div style="display: none;">
<stripes:form id="hidden.queryUploadFile" beanclass="<%=actionBean.getClass().getName() %>" method="post" >
	
	
	<stripes:hidden id="hidden.queryResult.pageNumber" name="queryResult.pageNumber" />
	<stripes:hidden id="hidden.queryResult.sortCriterion" name="queryResult.sortCriterion" />
	<stripes:hidden id="hidden.queryResult.sortDirection" name="queryResult.sortDirection" />
	<stripes:hidden id="hidden.deleteUploadFilePk" name="deleteUploadFilePk"/>
	<stripes:submit id="hidden.doQueryBtn" name="doQuery" value="查詢" class="formBtn"/>
	<stripes:submit id="hidden.doDeleteBtn" name="doDelete" value="刪除" class="formBtn"/>
	<stripes:errors></stripes:errors>
</stripes:form>
</div>

</body>
</html>
